package a10_动态规划;

import java.util.Arrays;

/**
 * <p>
 * a21_组合总和4复习2
 * </p>
 *
 * @author flyduck
 * @since 2025/2/27
 */
public class a21_组合总和4复习2 {

    public static void main(String[] args) {
        a21_组合总和4复习2 test = new a21_组合总和4复习2();
        int i = test.combinationSum4(new int[]{1, 2, 3}, 4);
    }

    //完全背包：顺序
    //dp[j]:和为j的有dp[j]种方式
    public int combinationSum4(int[] nums, int target) {
        int[] dp = new int[target+1];
        dp[0] = 1;

        for (int j = 0; j <= target; j++) {
            for (int i = 0; i < nums.length; i++) {
                if(j >= nums[i]){
                    dp[j] = dp[j] + dp[j-nums[i]];
                }
            }
        }

        return dp[target];
    }
}
